﻿@model DiscountModel
@inject AdminAreaSettings adminAreaSettings
@{
    <vc:admin-widget widget-zone="discount_details_history_top" additional-data="Model"/>
    <div id="usagehistory-grid"></div>
    <vc:admin-widget widget-zone="discount_details_history_bottom" additional-data="Model"/>
    <script>
        $(document).ready(function () {
            $("#usagehistory-grid").kendoGrid({
                dataSource: {
                    transport: {
                        read: {
                            url: "@Html.Raw(Url.Action("UsageHistoryList", "Discount", new { discountId = Model.Id, area = Constants.AreaAdmin }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        },
                        destroy: {
                            url: "@Html.Raw(Url.Action("UsageHistoryDelete", "Discount", new { area = Constants.AreaAdmin }))",
                            type: "POST",
                            dataType: "json",
                            data: addAntiForgeryToken
                        }
                    },
                    schema: {
                        data: "Data",
                        total: "Total",
                        errors: "Errors",
                        model: {
                            id: "Id",
                            fields: {
                                //do not implicitly specify all fields
                                //we do it only for fields which implicitly require it
                                //otherwise, they'll be formatted wrong way
                                CreatedOn: {type: "date" }
                            }
                        }
                    },
                    error: function(e) {
                        display_kendoui_grid_error(e);
                        // Cancel the changes
                        this.cancelChanges();
                    },
                    pageSize: @(adminAreaSettings.DefaultGridPageSize),
                    serverPaging: true,
                    serverFiltering: true,
                    serverSorting: true
                },
                pageable: {
                    refresh: true,
                    pageSizes: [@(adminAreaSettings.GridPageSizes)]
                },
                editable: {
                    confirmation: false,
                    mode: "inline"
                },
                scrollable: false,
                columns: [{
                    field: "CreatedOn",
                    title: "@Loc["admin.marketing.Discounts.History.CreatedOn"]",
                    width: 200,
                    type: "date",
                    format: "{0:G}"
                }, {
                    field: "OrderId",
                    title: "@Loc["admin.marketing.Discounts.History.Order"]",
                    width: 200,
                    template: '<a class="btn btn-sm btn-default" href="@Url.Action("Edit", "Order", new { area = Constants.AreaAdmin })/#=OrderId#"><i class="fa fa-search"></i> #=OrderNumber# - @Loc["Admin.Common.View"]</a>'
                }, {
                    field: "OrderTotal",
                    title: "@Loc["admin.marketing.Discounts.History.OrderTotal"]",
                    width: 200
                },{
                    command: {name: "destroy", text: "@Loc["Admin.Common.Delete"]"},
                    title: "@Loc["Admin.Common.Delete"]",
                    width: 100
                }]
            });
        });
    </script>
}